//
//  LJJTimeSingleTableView.m
//  shopTest
//
//  Created by 梁佳佳 on 2016/11/17.
//  Copyright © 2016年 梁佳佳. All rights reserved.
//

#import "LJJTimeSingleTableView.h"
#import "LJJSingleTableViewCell.h"
#import "LJJGroupTableViewCell.h"
#import "LJJSingleRootModel.h"
#import "LJJGroupTableViewCell.h"
#import "LJJGroupRootModel.h"

@interface LJJTimeSingleTableView ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation LJJTimeSingleTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.bounces = NO;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return self;
}
- (void)setSingleArray:(NSArray *)singleArray
{
    _singleArray = singleArray;
    [self reloadData];
}
- (void)setGroupArray:(NSArray *)groupArray
{
    _groupArray = groupArray;
    [self reloadData];
}
#pragma mark -
#pragma mark - tableView delegate & datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.isSingle) {
        return self.singleArray.count;
    }
    else
    {
        return self.groupArray.count;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isSingle) {
        return 170;
    }
    else
    {
        return 200;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.isSingle == YES) {
        static NSString *identifier = @"LJJTimeSingleCell";
        LJJSingleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[LJJSingleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        LJJSingleRootModel *model = self.singleArray[indexPath.row];
        cell.model = model;
        return cell;
    }
    else
    {
        static NSString *identifier = @"LJJTimeGroupCell";
        LJJGroupTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[LJJGroupTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        LJJGroupRootModel *model = self.groupArray[indexPath.row];
        cell.imageURL = model.ImgView;
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.isSingle) {
        if (self.goodsIDBlock) {
            LJJSingleRootModel *model = self.singleArray[indexPath.row];
            self.goodsIDBlock(model.GoodsId, model.CountryImg);
        }
    }
}

@end
